# -*-coding:utf-8-*-
import datetime
import socket
import time
import requests
from logging import getLogger
from ..memcachedconnection import memcachcon
from config import w_java_ip
web_logger = getLogger('web_logger')

ip = socket.gethostbyname(socket.gethostname())


def weixin_push(remark, content, title):
    # pass
    try:
        url = "http://" + str(w_java_ip) + "/wx_api2/rest/?action=sendEarlyWarningMessage&title='" + str(
            title) + "'&remark='" + str(remark) + "'&content='" + str(content) + "'&userid=2386"
        # print(url) #1963����  2386�׾�
        req = requests.post(url, timeout=2)
    except Exception as e:
        web_logger.error('cid:%s error:%s %s', type(e), e)


while True:
    time.sleep(60)
    # memcachcon.set_cach()
    if memcachcon.if_exist("not_request" + str(ip)) == None:
        the_begintime = time.strptime("9:00:00", "%H:%M:%S")
        the_endtime = time.strptime("21:00:00", "%H:%M:%S")
        the_now_tome = time.strptime(time.strftime("%H:%M:%S"), "%H:%M:%S")
        if the_begintime < the_now_tome <= the_endtime:
            print('ffdddrrrrrqq')
            weixin_push('�θ������', '�Ѿ�һ����û������', ip)

    else:
        memcachcon.del_cach("not_request" + str(ip))
